<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>小贷账单主表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">机构名称</div>
                    <div class="field">
                        <select name="loanId" id="loanId">
	                     <option selected="selected" value="">--全部--</option>
	                        <c:forEach items="${channelList }" var="ct">
	                        	<option value="${ct.id }">${ct.loanName }</option>
	                        </c:forEach>
                    	</select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">放款账户</div>
                    <div class="field">
                        <select name="accountId" id="accountId">
	                     <option selected="selected" value="">--全部--</option>
	                        <c:forEach items="${accountList }" var="ct">
	                        	<option value="${ct.id }">${ct.accountName }</option>
	                        </c:forEach>
                    	</select>
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
	                <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
             </div>
             <div class="fieldset1 clearFix">    
                <div class="fieldBox">
                    <div class="label">附件上传</div>
                    <div class="field">
                        <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                            <jsp:param name="filePath" value="/ass"/>
                        </jsp:include>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>


<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		//initEvent();
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url: '<%=path%>/mcr/mcrBillM/initUploadList.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '贷款合同号', name: 'crCntNo', minWidth: 110, align: 'left',
                    render:function(rowdata,index,value){
                        return '<a href="javascript:;" style="cursor: pointer;" onclick="billDtl('+rowdata.id+')">'+rowdata.crCntNo+'</a>';
                    }
                },
                {display: '贷款金额', name: 'crAmtStr', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.actCrAmt){
                            return '&yen;'+rowdata.crAmtStr;
                        }
                    }
                },
                {display: '实际放款金额', name: 'actCrAmtStr', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.actCrAmtStr){
                            return '&yen;'+rowdata.actCrAmtStr;
                        }
                    }
                },
                {display: '业务类型', name: 'loanBizTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '贷款类型', name: 'crTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '租赁期数', name: 'crPd', minWidth: 80, align: 'center',
                    render:function(rowdata,index,value){
                        return rowdata.crPd+rowdata.crPdUntCdNm;
                    }
                },
                {display: '放款日', name: 'crDtStr', minWidth: 100, align: 'center', },
                {display: '结清时间', name: 'stlDtStr', minWidth: 100, align: 'center', },
                {display: '贷款状态', name: 'loanStsCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '创建日期', name: 'crtTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	}
	
	
  	//Grid操作列
    function getGridOperColumnContent(){
  		var currentUserId = $("#currentUserId").val();
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
                render: function (rowdata, rowindex, value){
                     /* h='<a class="sq-button-hasicon" href="javascript:deleteRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'mid_man_grid_id'"
                        h+=")\"><i class=\"sqBtnIco_7\"></i>删除</a>" */
                        
                    var h='<a class="sq-button-hasicon" href="javascript:modifyRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'mid_man_grid_id'"
                        h+=")\"><i class=\"sqBtnIco_4\"></i>修改</a>"
                        
                    var m='<a class="sq-button-hasicon" href="javascript:audReturnVisit(';
                        m+="'"+rowdata.id+"',";
                        m+="'"+rowdata.carId+"',";
                        m+="'"+rowdata.usrId+"',";
                        m+="'"+'0'+"'";
                        m+=",'mid_man_grid_id'"
                        m+=")\"><i class=\"sqBtnIco_7\"></i>添加信审回访</a>"
                    var n='<a class="sq-button-hasicon" href="javascript:audReturnVisit(';
                    	n+="'"+rowdata.id+"',";
                    	n+="'"+rowdata.carId+"',";
                    	n+="'"+rowdata.usrId+"',";
                        n+="'"+'1'+"'";
                        n+=",'mid_man_grid_id'"
                        n+=")\"><i class=\"sqBtnIco_7\"></i>查看信审回访</a>";
                   	var z='<a class="sq-button-hasicon" href="javascript:cancel(';
                        z+="'"+rowdata.id+"'";
                        z+=",'mid_man_grid_id'"
                        z+=")\"><i class=\"sqBtnIco_7\"></i>作废</a>"
                    var y='<a class="sq-button-hasicon" href="javascript:claim(';
                        y+="'"+rowdata.id+"'";
                        y+=",'mid_man_grid_id'"
                        y+=")\"><i class=\"sqBtnIco_7\"></i>领取</a>"
                   	var returnStr = '';  
                   	if(rowdata.isDel == 0){
                       	returnStr = z;
                    }
                   	if(rowdata.claim != null && rowdata.claim != ''){
                   		if(rowdata.returnVisistId != null && rowdata.returnVisistId != ''){
                       		returnStr = returnStr + h + n;
                       	}else if(currentUserId == rowdata.claim){
                       		returnStr = returnStr + h + m;
                       	}else{
                       		returnStr = returnStr + h;
                       	}
                   	}else{
                   		returnStr = returnStr + y + h;
                   	}
                   	return returnStr;
                }
            }
    	return data;
	}
    //查看账单详情
    function billDtl(billId){
        Add_navTab('MCR_BILL_M_'+billId,'小贷账单详情',"<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id="+billId);
    }

    //查询客户详情
    function showCstDtl(_cstId){
        Add_navTab("MCR_BILL_M_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    
  //定义父级调用事件
	frameElement.dialog.onOk = function () {
		save();
	}
	
	frameElement.dialog.onCancel = function () {
		frameElement.dialog.close();
	}
	
  //新增
	function save(){
		var data = new Array();//获取表单数据
		var fileParams = getUploadResultParams();//获取附件上传的信息
        data["fileParams"] = JSON.stringify(fileParams);
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length < 1){
			UIUtils.alertError("请至少选择一条数据");
			return;
		}
		var ids = [];
		for(var i=0;i<selectedRows.length;i++){
			var id = selectedRows[i].id;
			ids[i] = id;
		}
		data["ids"] = JSON.stringify(ids);
        var url = '<%=path%>/mcr/mcrBillM/uploadPic.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {ids: JSON.stringify(ids) ,fileParams: JSON.stringify(fileParams)},
            url: url,
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    searchBtn();
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
	}
  
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
       grid.reload();
	}
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "loanId":"",
		    "accountId":""
		  });
	}
</script>

</body>
</html>
